import { ChinaJson } from './chinaMap/china'
import { Beijing_Json } from './chinaMap/province/beijing'
import { Tianjin_Json } from './chinaMap/province/tianjin'
import { Hebei_Json } from './chinaMap/province/hebei'
import { Liaoning_Json } from './chinaMap/province/liaoning'
import { Heilongjiang_Json } from './chinaMap/province/heilongjiang'
import { Jilin_Json } from './chinaMap/province/jilin'
import { Neimenggu_Json } from './chinaMap/province/neimenggu'
import { Xinjiang_Json } from './chinaMap/province/xinjiang'
import { Gansu_Json } from './chinaMap/province/gansu'
import { Qinghai_Json } from './chinaMap/province/qinghai'
import { Xizang_Json } from './chinaMap/province/xizang'
import { Ningxia_Json } from './chinaMap/province/ningxia'
import { Shanxi_Json } from './chinaMap/province/Shanxi'
import { ShanXii_Json } from './chinaMap/province/shanXii'
import { Shandong_Json } from './chinaMap/province/shandong'
import { Henan_Json } from './chinaMap/province/henan'
import { Jiangsu_Json } from './chinaMap/province/jiangsu'
import { Sichuan_Json } from './chinaMap/province/sichuan'
import { Chongqing_Json } from './chinaMap/province/chongqing'
import { Hubei_Json } from './chinaMap/province/hubei'
import { Shanghai_Json } from './chinaMap/province/shanghai'
import { Zhejiang_Json } from './chinaMap/province/zhejiang'
import { Jiangxi_Json } from './chinaMap/province/jiangxi'
import { Hunan_Json } from './chinaMap/province/hunan'
import { Guizhou_Json } from './chinaMap/province/guizhou'
import { Yunnan_Json } from './chinaMap/province/yunnan'
import { Guangxi_Json } from './chinaMap/province/guangxi'
import { Guangdong_Json } from './chinaMap/province/guangdong'
import { Taiwan_Json } from './chinaMap/province/taiwan'
import { Hainan_Json } from './chinaMap/province/hainan'
import { Xianggang_Json } from './chinaMap/province/xianggang'
import { Aomen_Json } from './chinaMap/province/aomen'
import { Anhui_Json } from './chinaMap/province/anhui'
import { Fujian_Json } from './chinaMap/province/fujian'



// 地图json
const mapDict = {
  'china': 'china',
  '北京市': 'beijing',
  '天津市': 'tianjin',
  '河北省': 'hebei',
  '黑龙江省': 'heilongjiang',
  '辽宁省': 'liaoning',
  '吉林省': 'jilin',
  '内蒙古自治区': 'neimenggu',
  '新疆维吾尔自治区': 'xinjiang',
  '甘肃省': 'gansu',
  '青海省': 'qinghai',
  '西藏自治区': 'xizang',
  '宁夏回族自治区': 'ningxia',
  '陕西省': 'shanxi',
  '山西省': 'shanxii',
  '山东省': 'shandong',
  '河南省': 'henan',
  '江苏省': 'jiangsu',
  '四川省': 'sichuan',
  '重庆市': 'chongqing',
  '湖北省': 'hubei',
  '安徽省': 'anhui',
  '上海市': 'shanghai',
  '浙江省': 'zhejiang',
  '江西省': 'jiangxi',
  '湖南省': 'hunan',
  '贵州省': 'guizhou',
  '云南省': 'yunnan',
  '福建省': 'fujian',
  '广东省': 'guangdong',
  '广西壮族自治区': 'guangxi',
  '海南省': 'hainan',
  '台湾省': 'taiwan',
  '香港特别行政区': 'xianggang',
  '澳门特别行政区': 'aomen'
}
const mapData = {
  'china': ChinaJson,
  'beijing': Beijing_Json,
  'tianjin': Tianjin_Json,
  'hebei': Hebei_Json,
  'heilongjiang': Heilongjiang_Json,
  'liaoning': Liaoning_Json,
  'jilin': Jilin_Json,
  'neimenggu': Neimenggu_Json,
  'xinjiang': Xinjiang_Json,
  'gansu': Gansu_Json,
  'qinghai': Qinghai_Json,
  'xizang': Xizang_Json,
  'ningxia': Ningxia_Json,
  'shanxi': Shanxi_Json,
  'shanxii': ShanXii_Json,
  'shandong': Shandong_Json,
  'henan': Henan_Json,
  'jiangsu': Jiangsu_Json,
  'sichuan': Sichuan_Json,
  'chongqing': Chongqing_Json,
  'hubei': Hubei_Json,
  'anhui': Anhui_Json,
  'shanghai': Shanghai_Json,
  'zhejiang': Zhejiang_Json,
  'jiangxi': Jiangxi_Json,
  'hunan': Hunan_Json,
  'guizhou': Guizhou_Json,
  'yunnan': Yunnan_Json,
  'fujian': Fujian_Json,
  'guangdong': Guangdong_Json,
  'guangxi': Guangxi_Json,
  'hainan': Hainan_Json,
  'taiwan': Taiwan_Json,
  'xianggang': Xianggang_Json,
  'aomen': Aomen_Json
}


export function getMap(mapName) {
  const cityName = mapDict[mapName]
  if(cityName){
    return [cityName,mapName, mapData[cityName]]
  }
  return ['china', 'china',ChinaJson]
}

export function getLineStatus(mapName){
  const success = ['北京市','江苏省','广东省','辽宁省']  // 指定省份，网络连接均正常
  const cityName = mapDict[mapName]
  var cityJson = []
  if(cityName){
    cityJson = mapData[cityName].features
  }else{
    cityJson = ChinaJson.features
  }
  const cityStatus = []
  for(let i = 0; i < cityJson.length; i++){
    const haveCenter = Object.keys(cityJson[i].properties).indexOf('center') > -1
    if(i == 0){
      haveCenter && cityJson[0].properties.center.push(1)
    }else{
      haveCenter && cityJson[i].properties.center.push(1)
    }
    let value = []
    let center =  []
    const coord = []
    value = cityJson[i].properties.center
    center =  cityJson[0].properties.center
    coord.push(center)
    coord.push(value)
    let obj = {}
    const isSuccess = success.indexOf(mapName) > -1
    obj.name = cityJson[i].properties.name
    obj.lineName = cityJson[0].properties.name + '-' + cityJson[i].properties.name
    obj.lineStatus = isSuccess || i % 2 == 0 ? 'success' : 'fail'
    obj.lineInfos = isSuccess || i % 2 == 0 ? '连接正常' : '连接失败'
    obj.value = value
    obj.coord = coord
    cityStatus.push(obj)
  }
  return cityStatus
}




